describe("Utility functions",function() {
	describe("Logger",function() {
		it("Can log messages", function() {
			var logSpy = spyOn(console,"log")
			MojaUtils.Logger.log("Testmessage");
			expect(console.log).toHaveBeenCalledWith("Testmessage");
		})
	});
		
	describe("ExArray",function() {
		var ExArray = new MojaUtils.ExArray();
		
		it("Can add unique items", function() {
			ExArray.addUniqueItem("Test");
			ExArray.addUniqueItem("Test");
			expect(ExArray.length).toEqual(1);			

			ExArray.addUniqueItem("Test2");
			expect(ExArray.length).toEqual(2);			
		});
		
		it("Can find items",function() {
			var result = ExArray.find("Test");	
			expect(result).toNotEqual(-1);
			
			var result = ExArray.find("NotExisting");	
			expect(result).toEqual(-1);
		});
		
		it("Can remove items",function() {
			ExArray.removeAt("Test");	
			ExArray.removeAt("Test2");
			expect(ExArray.length).toEqual(0);
		});
	});
	
	describe("Id creater", function() {
		var ExArray = new MojaUtils.ExArray();
		var items = 100;
		it("Can create unique ids", function() {
			for(var i = 0;i<items;i++) {
				ExArray.addUniqueItem(MojaUtils.Id())
			}
			expect(ExArray.length).toEqual(items);
		});
	});
	
	describe("EventHandler",function() {
		var observable = new MojaUtils.Observable();
		it("Can register and call Events", function() {
			this.fn = function(arg){}
			this.fnSingleShot = function(arg){}
			
			var fnSpy = spyOn(this,"fn");
			var fnSingleShotSpy = spyOn(this,"fnSingleShot");
			var args = ["test"]
			
			observable.registerEvent("fire",this.fn,this,false);
			observable.registerEvent("fire",this.fnSingleShot,this,true);
			observable.fireEvent("fire",args);
			
			expect(fnSpy).toHaveBeenCalledWith(args[0]);
			expect(fnSingleShotSpy).toHaveBeenCalledWith(args[0]);
		
			observable.fireEvent("fire",args);
			expect(fnSpy).callCount = 2;
			expect(fnSingleShotSpy).callCount == 1;
		});
		it("Can unregister events")
	})
	
	xdescribe("Websocket Access", function() {
		it("Runs on a Browser that supports WebSockets",function() {
			expect(WebSocket).toBeDefined();
		});
		var Socket = new MojaUtils.Socket();
		it("Can connect to a webserver socket",function() {

			Socket.connect(
				"ws://localhost",
				2000
			);
			var successSpy = spyOn(Socket.__Socket,"onopen");
			var failSpy = spyOn(Socket.__Socket,"onerror");
/*
			expect(failSpy).wasNotCalled();
			expect(successSpy).toHaveBeenCalled();*/
		}); 
	});
	
});
